package com.hoas.quickstart.threads.chapter06.chapter06_4_1;

import java.io.ObjectStreamException;
import java.io.Serializable;

public class MyObject implements Serializable {

    private static final long serialVersionUID = 888L;

    private static class MyObjectHandler {

        private static final MyObject myObject = new MyObject();

    }

    private MyObject() {
    }

    private MyObject instance;

    public static MyObject getInstance() {
        return MyObjectHandler.myObject;
    }

    /**
     * 此方法来解决反序列化的对象与单例对象不一致问题
     * @return
     * @throws ObjectStreamException
     */
    //private Object readResolve() throws ObjectStreamException {
        // instead of the object we're on,
        // return the class variable INSTANCE
    //    return MyObjectHandler.myObject;
    //}

}
